﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class city_s_forum_new : System.Web.UI.Page
{

    int no;

    protected void Page_Load(object sender, EventArgs e)
    {

        no = int.Parse(Request["no"]);

        ctp_lib.check_login(this.Page, "city_s_forum_new.aspx?no=" + no.ToString());


        if (!this.IsPostBack)
        {
            ctpDataContext db = new ctpDataContext();
            ct_s_profile cts = db.ct_s_profiles.Single(p => p.valid == true && p.no == no && p.language_no == (int)Session["now_user_lang_no"]);

            this.HyperLink3.Text = cts.title;
            this.HyperLink3.NavigateUrl = "city_s.aspx?no=" + no.ToString().Trim();
            this.HyperLink2.Text = cts.ct_profile.title.Trim();
            this.HyperLink2.NavigateUrl = "city.aspx?no=" + cts.ct_no;

            this.HyperLink9.NavigateUrl = "city_s_forum.aspx?no=" + no.ToString();

            this.ViewState["ct_no"] = cts.ct_no;

        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ctpDataContext db = new ctpDataContext();
        ct_s_forum myf=new ct_s_forum();

        myf.addtime=DateTime.Now;
        myf.create_user_no=(int)Session["userno"];
        myf.ct_no=(int)this.ViewState["ct_no"];

        myf.ct_s_no = no;
        myf.last_post = DateTime.Now;
        myf.text=this.TextBox2.Text;
        myf.title=this.TextBox1.Text;

        

        db.ct_s_forums.InsertOnSubmit(myf);
        db.SubmitChanges();

        var postdata = from p in db.ct_s_forums
                       where p.create_user_no == (int)Session["userno"]
                       orderby p.addtime descending
                       select p;

        int postno = postdata.First().no;

        DatabaseUtil my_util = new DatabaseUtil();
        my_util.writeTranslatedTxt((int)DatabaseUtil.fromTables.forum_text, postno, this.TextBox2.Text, "en");
        my_util.writeTranslatedTxt((int)DatabaseUtil.fromTables.forum_title, postno, this.TextBox1.Text, "en");


        Response.Redirect("city_s_forum.aspx?no="+no.ToString());



    }
}
